package com.tengju.settlement.infrastructure.persistence.redis;

import com.tengju.settlement.infrastructure.persistence.redis.dataobject.RedisKeyObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import java.util.concurrent.TimeUnit;


@Repository
public class DepositoryCacheRepository {

    @Autowired
    private RedisService redisService;

    /**
     * 设置绑卡验证的请求次数
     */
    public boolean setBindCardCnt(RedisKeyObject key, int bindEffectiveCnt, int expireHours) {
        return redisService.setValue(key, bindEffectiveCnt, expireHours, TimeUnit.HOURS) == 1;

    }

    public boolean bindCntIncr(RedisKeyObject key) {
        return redisService.valueIncrement(key) == 1;
    }

    public boolean existBindCardKey(RedisKeyObject key) {
        return redisService.hasKey(key);
    }

    public void delBindCardKey(RedisKeyObject key) {
        redisService.delKey(key);
    }

    public Integer getBindCardValue(RedisKeyObject key) {
        return redisService.get(key, Integer.class);
    }

    public Long getBindCardExpireTime(RedisKeyObject key) {
        return redisService.getExpireTime(key);
    }
}
